"use strict";
cc._RF.push(module, '4ca0bUyPLhDM5ah/6DmjQWN', 'monster_hp_node');
// scripts/monster_hp_node.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("AssetsManager"),
    i = cc._decorator,
    r = i.ccclass,
    s = i.property,
    l = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.hp_bar_mask = null, t.hp_bar_node = [], t.bar_num_label = null, t.monster_head_sprite = null, t.monster_type_label = null, t.monster_name_label = null, t.show_monster_id = -1, t.hp_bar_num = 0, t.show_tween_anime = !1, t.monster_max_hp = 0, t.monster_now_hp = 0, t.hp_color_list = [cc.color(50, 115, 210), cc.color(50, 210, 110), cc.color(210, 210, 50), cc.color(210, 120, 50), cc.color(210, 50, 60), cc.color(210, 50, 200)], t;
  }

  return nn(t, e), t.prototype.initView = function () {
    this.show_tween_anime = !1, this.show_monster_id = -1, this.hp_bar_mask.zIndex = 10;
  }, t.prototype.showMonsterHpInfo = function (e) {
    -1 != this.show_monster_id && e.monster_id != this.show_monster_id || (-1 == this.show_monster_id && (this.monster_head_sprite.spriteFrame = n["default"].getInstance().getGameHoreHeadFrame(e.head), this.monster_name_label.string = e.name + e.monster_id, this.hp_bar_num = Math.floor(e.max_hp / 800), this.bar_num_label.string = "" + this.hp_bar_num, this.show_monster_id = e.monster_id, this.hp_bar_node[0].width = 800, this.hp_bar_node[1].width = e.max_hp - 800 * this.hp_bar_num, this.monster_max_hp = this.monster_now_hp = e.max_hp, this.showHpBarColor()), e.monster_id == this.show_monster_id && (this.monster_now_hp -= Number(e.hit_num), this.show_tween_anime || (this.show_tween_anime = !0, this.showBarAnime())));
  }, t.prototype.showBarAnime = function () {
    var e = this,
        t = this.monster_max_hp - this.monster_now_hp;
    t = Math.floor(t / 800) > 0 ? this.hp_bar_node[1].width : t > this.hp_bar_node[1].width ? this.hp_bar_node[1].width : t, cc.tween(this.hp_bar_node[1]).by(t / 1600, {
      width: -1 * t
    }).call(function () {
      if (e.monster_max_hp -= t, e.monster_now_hp != e.monster_max_hp) {
        if (e.hp_bar_node[1].width <= 0) {
          if (e.hp_bar_num--, e.showHpBarColor(), !(e.hp_bar_num >= 0)) return void (e.node.active = !1);
          e.bar_num_label.string = "" + e.hp_bar_num, e.hp_bar_node[1].width = 800;
        }

        e.showBarAnime();
      } else e.monster_now_hp > 0 ? (e.show_tween_anime = !1, e.show_monster_id = -1) : e.node.active = !1;
    }).start();
  }, t.prototype.showHpBarColor = function () {
    var e = (this.hp_bar_num + 1) % 5,
        t = e <= 0 ? 5 : e - 1;
    this.hp_bar_node[0].color = this.hp_color_list[e], this.hp_bar_node[1].color = this.hp_color_list[t];
  }, oo([s(cc.Node)], t.prototype, "hp_bar_mask", void 0), oo([s(cc.Node)], t.prototype, "hp_bar_node", void 0), oo([s(cc.Label)], t.prototype, "bar_num_label", void 0), oo([s(cc.Sprite)], t.prototype, "monster_head_sprite", void 0), oo([s(cc.Label)], t.prototype, "monster_type_label", void 0), oo([s(cc.Label)], t.prototype, "monster_name_label", void 0), oo([r], t);
}(a["default"]);

o["default"] = l;

cc._RF.pop();